package com.qzsoft.zhjd.materiel.modules.materielweighttype.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.materiel.modules.materielweighttype.dto.MaterielWeightTypeDto;
import com.qzsoft.zhjd.materiel.modules.materielweighttype.entity.MaterielWeightTypeEntity;
import com.qzsoft.zhjd.materiel.modules.materielweighttype.service.MaterielWeightTypeService;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequestMapping("/materiel/weight")
@Api(tags = "过磅类型")
public class MaterielWeightTypeController {

    @Autowired
    private MaterielWeightTypeService weightTypeService;

    /**
     * @return 操作结果
     * @Description: 保存过磅类型数据
     * @Author:wang_hyu
     */
    @PostMapping("/saveTypeInfo")
    @RequiresPermissions("materiel:weight:page")
    public Result<String> saveTypeInfo(@RequestBody MaterielWeightTypeDto weightTypes) {
        weightTypeService.saveTypeInfo(weightTypes);
        Result<String> results = ResultUtils.ok();
        return results;
    }

//    /**
//     * 访问url获取、保存过磅类型数据
//     * @Author wang_hyu
//     * @date :2022年1月18日
//     */
//    @GetMapping("/urlSaveInfo")
//    @RequiresPermissions("materiel:weight:page")
//    public Result<String> getUrlInfo() throws IOException {
//        weightTypeService.getUrlInfo();
//        Result<String> results = ResultUtils.ok();
//        return results;
//    }


    /**
     * @Description: 获取过磅类型列表数据信息
     * @Author:wang_hyu
     */
    @GetMapping("/listInfo")
    @RequiresPermissions("materiel:weight:page")
    public Result<IPage<MaterielWeightTypeDto>> listInfo(@RequestParam Map<String, Object> params) {
        IPage<MaterielWeightTypeDto> weightTypes = weightTypeService.listByPage(params);

        Result<IPage<MaterielWeightTypeDto>> results = new Result<IPage<MaterielWeightTypeDto>>();
        results.setData(weightTypes);
        return results;
    }

    /**
     * @Description:根据id查询过磅详情信息
     * @Author:wang_hyu
     */
    @GetMapping("/infoDetails/{id}")
    @RequiresPermissions("materiel:weight:page")
    public Result<MaterielWeightTypeEntity> infoDetails(@PathVariable("id") String id) {
        MaterielWeightTypeEntity weightType = weightTypeService.infoDetails(id);

        Result<MaterielWeightTypeEntity> results = new Result<MaterielWeightTypeEntity>();
        results.setData(weightType);
        return results;
    }

    /**
     * @return 操作结果
     * @Description: 更新过磅类型数据
     * @Author:wang_hyu
     */
    @PostMapping("/updateTypeInfo")
    @RequiresPermissions("materiel:weight:page")
    public Result<String> updateTypeInfo(@RequestBody MaterielWeightTypeDto weightTypes) {
        weightTypeService.updateTypeInfo(weightTypes);
        Result<String> results = ResultUtils.ok();
        return results;
    }

    /**
     * @return 操作结果
     * @Description: 根据id删除过磅类型数据
     * @Author:wang_hyu
     */
    @RequiresPermissions("materiel:weight:page")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable("id") String id) {
        weightTypeService.removeById(id);
        return ResultUtils.ok();
    }

}
